package com.ruoyi.quartz.task;

import com.ruoyi.hd.domain.HdCommodity;
import com.ruoyi.hd.domain.HdCommodityTime;
import com.ruoyi.hd.mapper.HdCommodityMapper;
import com.ruoyi.hd.mapper.HdCommodityTimeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.List;

/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Service
@Component("hdTask")
@EnableAsync
public class HdTask
{
    @Autowired
    private HdCommodityMapper hdCommodityMapper;
    @Autowired
    private HdCommodityTimeMapper hdCommodityTimeMapper;

//    @Async("setHdcommodityTimeByCommodityIdTaskExecutor")
    public void setHdcommodityTimeByCommodityId(){
        List<HdCommodity> list = hdCommodityMapper.selectHdCommodityList(new HdCommodity());
        list.forEach(item->{
            HdCommodityTime commodityTime = new HdCommodityTime();
            commodityTime.setName(item.getName());
            List<HdCommodityTime> hdCommodityTimes = hdCommodityTimeMapper.selectHdCommodityTimeList(commodityTime);
            hdCommodityTimes.forEach(items->{
                if (ObjectUtils.isEmpty(items.getCommodityId())){
                    items.setCommodityId(item.getId().toString());
                    hdCommodityTimeMapper.updateHdCommodityTime(items);
                }
            });
        });
    }
}
